package cn.seven._conf._jfinal;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.template.ext.spring.JFinalViewResolver;
import com.jfinal.template.source.ClassPathSourceFactory;

@Configuration
public class JFinalViewConfig {

    @Bean(name = "jfinalViewResolver")
	public JFinalViewResolver getJFinalViewResolver() {
		JFinalViewResolver jfr = new JFinalViewResolver();
		// 是否开启热加载
		jfr.setDevMode(PropKit.getBoolean("engineDevMode"));
		jfr.setSourceFactory(new ClassPathSourceFactory());
//		String webRootPath = PathKit.getRootClassPath() + "/templates";
//		// 设置模板文件基础路径
//		jfr.setBaseTemplatePath(webRootPath); 
		// 在页面中可以使用 #(session.value)
		jfr.setSessionInView(true);
		
		jfr.setSuffix(".html");
		jfr.setPrefix("/templates/");
		jfr.setContentType("text/html;charset=UTF-8");
		jfr.setOrder(0);
		
		jfr.addSharedObject("ctx", PropKit.get("ctx"));
		jfr.addSharedObject("sk", new StrKit());
		return jfr;
	}

}
